@echo off
setlocal enabledelayedexpansion

:: 设置命令行编码为 UTF-8
chcp 65001

:: 设置环境变量
set REPO_URL=registry.cn-chengdu.aliyuncs.com/yikejie
set IMAGE_NAME=fishstation


:: 获取当前时间戳，格式为 yyyyMMdd-HHmmss
for /f "tokens=1-2 delims=." %%a in ('wmic os get localdatetime ^| find "."') do (
    set datetime=%%a
)

set YEAR=%datetime:~0,4%
set MONTH=%datetime:~4,2%
set DAY=%datetime:~6,2%
set HOUR=%datetime:~8,2%
set MINUTE=%datetime:~10,2%
set SECOND=%datetime:~12,2%

set VERSION=%YEAR%%MONTH%%DAY%-%HOUR%%MINUTE%%SECOND%

echo 当前版本号: %VERSION%

:: 构建 Docker 镜像
echo 构建 Docker 镜像...
docker build -t %REPO_URL%/%IMAGE_NAME%:%VERSION% .

:: 检查构建是否成功
if %errorlevel% neq 0 (
    echo 镜像构建失败，退出...
    pause
    exit /b 1
)

:: 推送 Docker 镜像
echo 推送 Docker 镜像到仓库...
docker push %REPO_URL%/%IMAGE_NAME%:%VERSION%

:: 检查推送是否成功
if %errorlevel% neq 0 (
    echo 镜像推送失败，退出...
    pause
    exit /b 1
)
echo 镜像地址：%REPO_URL%/%IMAGE_NAME%:%VERSION%
echo 操作成功完成
pause
endlocal
